@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.adminList')}}">管理员管理</a>
            <em>></em>
            <a href="#">管理员设置</a>
        </div>
        <!-- cur-position end -->

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="rechargepackageid" value="@if($thisRechargePackage){{$thisRechargePackage->id}}@endif"/>
                <div class="gg-list">
                    <label class="tit">套餐名称</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入套餐名称" name="name" id="name" value="@if($thisRechargePackage){{$thisRechargePackage->name}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-50个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">套餐金额</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入套餐金额" name="amount_money" id="amount_money" value="@if($thisRechargePackage){{$thisRechargePackage->amount_money}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入数值（整数或小数）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">阅读币数量</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入阅读币数量" name="books_coin" id="books_coin" value="@if($thisRechargePackage){{$thisRechargePackage->books_coin}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入数值（整数）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">赠送的阅读币数量</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入赠送的阅读币数量" name="gift_books_coin" id="gift_books_coin" value="@if($thisRechargePackage){{$thisRechargePackage->gift_books_coin}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入数值（整数）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">备注</label>
                    <div class="cont">
                        <textarea name="remark" id="remark" cols="70" rows="10">@if($thisRechargePackage){{$thisRechargePackage->remark}}@endif</textarea>
                        <p class="text">可输入4-100个字符（一个汉字等于两个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">排序</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入排序" name="sort" id="sort" value="@if($thisRechargePackage){{$thisRechargePackage->sort}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入数值（整数）,从0开始，数值越小越靠前</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">状态</label>
                    <div class="cont">
                        <select name="status" id="status">
                            <option value="0" @if($thisRechargePackage && $thisRechargePackage->status == 0)selected @endif>下架</option>
                            <option value="1" @if($thisRechargePackage && $thisRechargePackage->status == 1)selected @endif>上架</option>
                        </select>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {
            $(document).on('click', '#btn-set', function () {
                var name            = $('#name').val();
                var amountMoney     = $('#amount_money').val();
                var booksCoin       = $('#books_coin').val();
                var giftBookCoin    = $('#gift_books_coin').val();
                var remark          = $('#remark').val();
                var sort            = $('#sort').val();
                var status          = $('#status option:selected').val();
                var id              = $('#rechargepackageid').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.setRechargePackage")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        name: name,
                        amount_money: amountMoney,
                        books_coin: booksCoin,
                        gift_books_coin: giftBookCoin,
                        remark: remark,
                        sort: sort,
                        status: status,
                        id:id

                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.href = "{{route('Admin.Home.rechargePackageList')}}";
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });


        });
    </script>
@endsection